//
//  ELVerticalChainLabel.swift
//  WZApp
//
//  Created by evol on 2018/7/26.
//  Copyright © 2018年 evol. All rights reserved.
//

import UIKit

// 垂直链式Label 多个label组成一个View
class ELVerticalChainLabel: UIView {
    init(text:String!, font: UIFont = UIFont.systemFont(ofSize: 15), textColor: UIColor = .black, space: CGFloat = 0){
        super.init(frame: .zero)
        self.width = font.pointSize + 1

        var lastTop:CGFloat = 0
        var maxWidth:CGFloat = 0
        for c in text {
            let label = UILabel()
            label.textColor = textColor
            label.font = font
            label.text = String(c)
            addSubview(label)
            if c.isChinese == false { //如果不是汉字 旋转
                label.transform =  CGAffineTransform(rotationAngle: CGFloat.pi/2)
            }
            label.sizeToFit()
            label.centerX = self.width/2
            label.top = lastTop == 0 ? lastTop : lastTop+space
            lastTop = label.frame.maxY
            if label.width > maxWidth {
                maxWidth = label.width
            }
        }
        self.height = lastTop
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
